package csp;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test1 {
	
	public static void main(String[] args) {
		//定义变量值
		List<String> variables = List.of("A","B","C","D","E","F","G");
		//定义值域
		Map<String,List<String>> domains = new HashMap<>();
		for (String variable:variables) {
			domains.put(variable, List.of("red","green","blue"));
		}
		//定义约束（相对定义变量值和定义值域来说是最难的部分）
		CSP<String,String> csp = new CSP<>(variables,domains);
		csp.addConstraint(new MapColoringConstraint("A","B"));
		csp.addConstraint(new MapColoringConstraint("A","C"));
		csp.addConstraint(new MapColoringConstraint("C","B"));
		csp.addConstraint(new MapColoringConstraint("D","B"));
		csp.addConstraint(new MapColoringConstraint("D","C"));
		csp.addConstraint(new MapColoringConstraint("D","E"));
		csp.addConstraint(new MapColoringConstraint("E","C"));
		csp.addConstraint(new MapColoringConstraint("F","C"));
		csp.addConstraint(new MapColoringConstraint("F","E"));
		csp.addConstraint(new MapColoringConstraint("F","G"));
		//解决方案
		Map<String,String> solution = csp.backtrackingSearch(new HashMap<String,String>());
		if (solution == null || solution.size() == 0) {
			System.out.println("No solution found!");
		} else {
			//{A=red, B=green, C=blue, D=red, E=green, F=red, G=green}
			System.out.println(solution);
		}
	}
	
}
